<!DOCTYPE html>
<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>Document</title>
</head>

<body>
   <form action="">
      用户名: <input type="text" name="username"> <br>
      <input type="submit">
   </form>

   <script>
      var form = document.forms[0];
      var btnSubmit = form.elements[1];
      console.log(btnSubmit);

      btnSubmit.onclick = function (e) {
         //阻止submit自动提交
         e.preventDefault();
         alert("自己用ajax发送异步请求,不刷新整个页面");
      }
   </script>

</body>

</html>